package com.magicsoft.share.wxapi;

import android.content.Intent;

import com.magicsoft.share.base.BaseActivity;
import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.utils.ToastUtils;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;


/**
 * @Author hwg
 * @Description：
 * @Date 2018/1/16
 */
public class WXPayEntryActivity extends BaseActivity implements IWXAPIEventHandler {

    private IWXAPI api;

    @Override
    public BasePresenter initPresenter() {
        return null;
    }

    @Override
    public int getLayoutId() {
        return 0;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        api = WXAPIFactory.createWXAPI(this, "wxd697852a3ab67ee8", false);
        api.registerApp("wxd697852a3ab67ee8");
        api.handleIntent(getIntent(), this);
    }

    @Override
    public void requestData() {

    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public  void onResp(BaseResp baseResp) {

        switch (baseResp.errCode) {

            //支付成功
            case 0:
                ToastUtils.showToast(this, "支付成功");
                break;

            //支付失败
            case -1:
                ToastUtils.showToast(this, "支付失败");
                break;

            //支付取消
            case -2:
                ToastUtils.showToast(this, "支付取消");
                break;

            default:

                break;

        }

        finish();

    }

}
